import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;

public class ButtonColumn extends AbstractCellEditor
	implements TableCellRenderer, TableCellEditor, ActionListener
{
	private JTable table;
	private AbstractAction action;
	private int mnemonic;

	private JButton renderButton;
	private JButton editButton;
	private Object editorValue;

	public ButtonColumn(JTable table, AbstractAction delete, int column)
	{
		this.table = table;
		this.action = delete;

		renderButton = new JButton("Pay Bill");
		editButton = new JButton("Pay Bill");
		editButton.setFocusPainted( false );
		editButton.addActionListener( this );
		
		TableColumnModel columnModel = table.getColumnModel();
		columnModel.getColumn(column).setCellRenderer( this );
		columnModel.getColumn(column).setCellEditor( this );
		
	}


	@Override
	public Component getTableCellEditorComponent(
		JTable table, Object value, boolean isSelected, int row, int column)
	{
		
		editButton.setText("Pay Bill");
		
		this.editorValue = value;
		return editButton;
	}

	@Override
	public Object getCellEditorValue()
	{
		return editorValue;
	}

//
//  Implement TableCellRenderer interface
//
	public Component getTableCellRendererComponent(
		JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
	{
		renderButton.setText("Pay Bill");

		return renderButton;
	}

	/*	
	 * Implement ActionListener interface
	 *	The button has been pressed. Stop editing and invoke the custom Action
	 */
	public void actionPerformed(ActionEvent e)
	{
		int row = table.convertRowIndexToModel( table.getEditingRow() );
		
		//  Invoke the Action

		ActionEvent event = new ActionEvent(table,ActionEvent.ACTION_PERFORMED, "paybill");
		action.actionPerformed(event);
	}

}
